﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Settings : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!User.IsInRole("Administrator"))
        {
            Response.Redirect("Default.aspx");
        }
        this.loadHostInfo();

    }
    protected void Click_Logout(object sender, EventArgs e)
    {
        System.Web.Security.FormsAuthentication.SignOut();
        Response.Redirect("Login.aspx");
    }

    protected void loadHostInfo()
    {
        TimeTrackerDataContext context = new TimeTrackerDataContext();

        try
        {
            var host = (from h in context.HostInformations
                        select h).SingleOrDefault();

            this.TextBoxAddress.Text = host.Address;
            this.TextBoxCity.Text = host.City;
            this.TextBoxCompany.Text = host.Name;
            this.TextBoxEmailAddress.Text = host.contactEmail;
            this.TextBoxFax.Text = host.fax;
            this.TextBoxPhone.Text = host.phone;
            this.TextBoxState.Text = host.State;
            this.TextBoxZip.Text = host.Zip;


        }
        catch (Exception ex)
        {

        }

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        TimeTrackerDataContext context = new TimeTrackerDataContext();

        try
        {
            var host = (from h in context.HostInformations
                        select h).SingleOrDefault();

            host.Address = this.TextBoxAddress.Text;
            host.City = this.TextBoxCity.Text;
            host.Name = this.TextBoxCompany.Text;
            host.contactEmail = this.TextBoxEmailAddress.Text;
            host.fax = this.TextBoxFax.Text;
            host.phone = this.TextBoxPhone.Text;
            host.State = this.TextBoxState.Text;
            host.Zip = this.TextBoxZip.Text;

        }
        catch (Exception ex)
        {
            HostInformation host = new HostInformation();

            host.Address = this.TextBoxAddress.Text ;
            host.City = this.TextBoxCity.Text;
            host.Name = this.TextBoxCompany.Text;
            host.contactEmail = this.TextBoxEmailAddress.Text;
            host.fax = this.TextBoxFax.Text;
            host.phone = this.TextBoxPhone.Text;
            host.State = this.TextBoxState.Text;
            host.Zip = this.TextBoxZip.Text;

            context.HostInformations.InsertOnSubmit(host);
        }

        context.SubmitChanges();
    }
}